import re
import unittest

def remove_leading(needle, haystack):
    """Remove leading needle string (if exists).

    >>> remove_leading('Test', 'TestThisAndThat')
    'ThisAndThat'
    >>> remove_leading('Test', 'ArbitraryName')
    'ArbitraryName'
    """
    if haystack[:len(needle)] == needle:
        return haystack[len(needle):]
    return haystack

def camel2word(string):
    """Covert name from CamelCase to "Normal case".

    >>> camel2word('CamelCase')
    'Camel case'
    >>> camel2word('CaseWithSpec')
    'Case with spec'
    """
    def wordize(match):
        return ' ' + match.group(1).lower()

    return string[0] + re.sub(r'([A-Z])', wordize, string[1:])

def complete_english(string):
    """
    >>> complete_english('dont do this')
    "don't do this"
    >>> complete_english('doesnt is matched as well')
    "doesn't is matched as well"
    """
    return string.replace('dont', "don't").replace('doesnt', "doesn't")

def underscore2word(string):
    return string.replace('_', ' ')

class TestCaseWithSpec(unittest.TestCase):
    def shortDescription(self):
        return "%s %s" % (getattr(self, 'context', None) or camel2word(remove_leading('Test', self.__class__.__name__)),
                          complete_english(underscore2word(remove_leading('test_', getattr(self, '_TestCase__testMethodName')))))
